home *** CD-ROM | disk | FTP | other *** search
/ Workbench Add-On / Workbench Add-On - Volume 1.iso / BBS-Archive / Dev / GNU-TILE-FORTH.lha / README < prev    next >
Text File  |  1992-05-19  |  15KB  |  382 lines

  1. THREADED INTERPRETIVE LANGUAGE ENVIRONMENT (TILE) FORTH
  2.  
  3. RELEASE 2.1
  4.  
  5. August 20, 1990
  6.  
  7. Mikael R.K. Patel
  8. Computer Aided Design Laboratory (CADLAB)
  9. Department of Computer and Information Science
  10. Linkoping University
  11. S-581 83 LINKOPING
  12. SWEDEN
  13. Email: mip@ida.liu.se
  14.  
  15.  
  16. 1.    INTRODUCTION
  17.  
  18. TILE Forth is a 32-bit implementation of the Forth-83 Standard 
  19. written in C. Thus allowing it to be easily moved between different 
  20. computers compared to traditional Forth implementations in assembly.
  21.  
  22. Most Forth implementations are done in assembly to be able to
  23. utilize the underlying architecture as optimal as possible. TILE 
  24. Forth goes another direction. The main idea behind TILE Forth is to 
  25. achieve a portable forth implementation for workstations and medium 
  26. size computer systems so that new groups of programmers may be exposed 
  27. to the flavor of an extensible language such as Forth. 
  28.  
  29. The implementation of TILE Forth is selected so that, in principle, 
  30. any C-level procedure may become available on the interactive and
  31. incremental forth level. Other models of implementation of a threaded
  32. interpreter in C are possible but these are not as flexible.
  33.  
  34. TILE Forth is organized as a set of modules to allow the kernel to be 
  35. used as a general threading engine for C. Environment dependencies such
  36. as memory allocation, error handling and input/output have been separated
  37. out of the kernel to increase flexibility. The forth application is "just"
  38. an example of how to use the kernel.
  39.  
  40. Comparing forth implementations using the traditional benchmarks such as
  41. the classical sieves calculation is difficult because of the difference 
  42. in speed between workstations and personal computers. The Byte sieves
  43. benchmark is reported to typically run in 16 seconds on a direct threaded
  44. forth implementation. This benchmark will run in 17 seconds in TILE forth 
  45. (compiled with GNU CC and optimized) on a SUN-3/60 and less than 9 seconds
  46. on a SUN SPARCstation 1. These times are the total time for loading TILE
  47. forth, compiling and executing the benchmark. Comparing to, for instance,
  48. other interpretive languages such as Lisp, where one of the classical 
  49. benchmarks is calculation of the Fibonacci function, the performance 
  50. increase is over a magnitude.
  51.  
  52. The kernel supports the Standard Forth-83 word set except for the
  53. blocks file word set which are not used. The kernel is extended with
  54. many of the concepts from modern programming languages. Here is a list
  55. of some of the extensions; argument binding and local variables, queue
  56. management, low level compiler words, string functions, floating point
  57. numbers, exceptions and multi-tasking. The TILE Forth environment also
  58. contains a set of reusable source files for high level multi-tasking, 
  59. data description and structuring modules, and a number of programming 
  60. tools.
  61.  
  62. To allow interactive and incremental program development TILE Forth
  63. includes a programming environment as a mode in GNU Emacs. This environ-
  64. ment helps with program structuring, documentation search, and program
  65. development. Each vocabulary in the kernel and the source library file is 
  66. described by a manual, documentation and test file. This style of 
  67. programming is emphasized throughout the environment to increase 
  68. understanding and reusability of the library modules. During compilation
  69. TILE Forth's io-package keeps track for which modules have been loaded
  70. so that they are only loaded once even if included by several modules.
  71.  
  72. Writing a Forth in C gives some possibilities that normally are
  73. not available when performing the same task in assembly. TILE Forth
  74. has been profiled using the available tools under Unix. This information
  75. has been used to optimize the compiler so that it achieves a compilation
  76. speed of over 200.000 lines per minute on my machine (a disk-less SUN
  77. SPARCstation 1). Currently code is only saved in source form and 
  78. applications are typically "compile-and-go".
  79.  
  80. So far TILE Forth has been ported and tested at over forty locations
  81. without any major problems except where C compilers do not allow sub-
  82. routine pointers in data structures. 
  83.  
  84.  
  85. 2.    EXTENSIONS
  86.  
  87. What is new in TILE forth? First of all the overall organization of
  88. words. To increase portability and understanding of forth code modules
  89. vocabularies are used as the primary packaging mechanism. New data types
  90. such as rational and floating point numbers are implemented in separate
  91. vocabularies. The vocabularies act as both a program module and an 
  92. abstract data type.
  93.  
  94. 2.1    Extensible interpreter
  95.  
  96. To allow extension of the literal symbol set (normally only integer
  97. numbers) each vocabulary is allowed to have a literal recognition
  98. function. This function is executed by the interpreter when the symbol
  99. search has failed. The literal recognizer for the forth vocabulary is 
  100. "?number". This simple mechanism allows modules such as for rational and 
  101. floating point numbers, and integer ranges to extend with their own
  102. literal function.
  103.  
  104. 2.2    Data description
  105.  
  106. As the Forth-83 Standard lack tools for description of data structures 
  107. TILE Forth contains a fairly large library of tools for this purpose. 
  108. These are described more in detail in the next section.
  109.  
  110. 2.3    Argument binding and local variables
  111.  
  112. When writing a forth function with many arguments stack shuffling
  113. becomes a real pain. Argument binding and local variables is a nice
  114. way out of these situations. Also for the new-comer to Forth this
  115. gives some support to this at first very cryptic language. Even
  116. the stack function may be rewritten using this mechanism:
  117.  
  118.     : 2drop { a b } ;
  119.     : 2swap { a b c d } c d a b  ;
  120.     : fac { n } n 0> if n 1- recurse n * else 1 then ;
  121.  
  122. The argument frame is created on top of the parameter stack and is
  123. disposed when functions is exited. This implementation style of
  124. reduces the cost of binding as most functions have more arguments
  125. then return values. A minimum number of data elements have to be
  126. move to create and manage the argument frame.
  127.  
  128. 2.4     Exception handling
  129.  
  130. Another extension in TILE Forth is exception handling with multiple
  131. exception handling code block. The syntactical structure is very
  132. close to that of Ada, i.e., any colon definition may contain an error
  133. handling section. Should an error occur during the execution of the
  134. function the stack status is restore to the situation at the call
  135. of the function and the latest exception block is executed with the 
  136. signal or exception as a parameter;
  137.  
  138.     exception zero-divide ( -- exception)
  139.  
  140.     : div ( x y -- z)
  141.           /
  142.     exception> ( x y signal -- )
  143.       drop zero-divide raise
  144.         ;
  145.  
  146. Error situations may be indicated using an exception raise function. 
  147. Low level errors, such as zero division, are transformed to exceptions 
  148. in TILE Forth.
  149.  
  150. 2.5    Entry visibility and forward declaration
  151.  
  152. Last, some of the less significant extension are forward declaration
  153. of entries, hidden or private entries, and extra entry modes. Forward
  154. declaration of entries are automatically bound when the entry is later
  155. given a definition. Should a binding not exist at run-time an error
  156. message is given and the computation is aborted.
  157.  
  158.     forward eval ( ... )
  159.  
  160.     : apply ( ... ) ... eval ... ;
  161.     : eval ( ... ) ... apply ... ;
  162.  
  163. Three new entry modes have been added to the classical forth model 
  164. (immediate). These allow hiding of entries in different situations.
  165. The first two marks the last defined words visibility according to
  166. an interpreter state. These two modifiers are called "compilation" 
  167. and "execution" and are used as "immediate". A word like "if" is
  168. "compilation immediate" meaning it is visible when compiling and 
  169. then always executed. 
  170.  
  171.     compiler forth definitions
  172.  
  173.     : if ( -- ) compile (?branch) >mark ; compilation immediate
  174.  
  175. The "private" modifier is somewhat different. It concerns the
  176. visibility across vocabularies (modules and types). If a word is
  177. marked as "private" the word is only visible when the vocabulary in 
  178. which it is defined in is "current". This is very close to the concept
  179. of hidden in modules and packages in Modula-2 and Ada.
  180.  
  181.     4 field +name ( entry -- addr) private
  182.  
  183. The above definition will only be visible in the vocabulary it was 
  184. defined. The "private" modifier is useful to help isolate implementation
  185. dependencies and reduce the name space which also increases compilation
  186. speed.
  187.  
  188.  
  189. 3.     SOURCE LIBRARY
  190.  
  191. The TILE Forth programming environment contains a number of tools to 
  192. make programming in Forth a bit easier. If you have GNU Emacs, TILE 
  193. Forth may run in a specialized forth-mode. This mode supports automatic 
  194. program indentation (pretty printing), documentation search, and 
  195. interactive and incremental program development, or "edit-compile-test" 
  196. style of program development.
  197.  
  198. To aid program development there is also a source code library with
  199. manual pages, documentation (glossary), and test and example code.
  200. Most of the source code are data modeling tools. In principle, from 
  201. bit field definition to object oriented structures are available. The 
  202. source code library also contains debugging tools for tracing, break-
  203. point'ing and profiling of programs. 
  204.  
  205. The first level of data modeling tools are modules for describing;
  206. 1) bit fields, 2) structures (records), 3) aggregates of data 
  207. (vectors, stacks, buffers, etc), 4) high level data objects
  208. (lists, sets, etc), and last, 5) object oriented programming with
  209. the three major models (relations, prototypes, and classes/instances).
  210.  
  211. The next level of tools are some tools for high level syntactic sugar
  212. for multi-tasking concepts (semaphores, channels, etc), anonymous code
  213. block (blocks), a general top down parser with backtrack and semantic
  214. binding, and a simulation package. The source library will be extended
  215. during the coming releases.
  216.  
  217.  
  218. 4.     PROGRAMMING STYLE
  219.  
  220. A source code module has, in general, the following structure; the 
  221. first section includes any modules needed (these are only loaded once).
  222. Second follows global definitions for the module. Normally this is 
  223. a vocabulary for the module. Third comes the search chain to be used
  224. throughout the module. It is important not to change the search order
  225. as 1) it becomes difficult for a reader to understand the code, 2)
  226. any change in the search chain flushes the internal lookup cache
  227. in TILE Forth and reduces compilation speed.
  228.  
  229.     .( Loading the Library...) cr
  230.  
  231.     #include someLibrary.f83
  232.     ...
  233.  
  234.     ( Global data and code definitions)
  235.  
  236.     : aGlobalDefinitions ( -- ) ... ;
  237.  
  238.     vocabulary theLibrary
  239.  
  240.     someLibrary ... theLibrary definitions
  241.  
  242.     ( Local data and code definitions)
  243.  
  244.     : aPrivateDefinitions ( -- ) ... ; private
  245.     ...
  246.     : aDefinitions ( -- ) ... ; 
  247.  
  248.     forth only
  249.  
  250. To create lexical levels within the same vocabulary the word "restore" 
  251. may be used. It stores the vocabulary pointer to the given entry and 
  252. thus hides the words defined after this entry. The word "restore" has 
  253. much the same action as "forget" but without putting back the dictionary 
  254. pointer.
  255.  
  256.  
  257. 5.    SOURCE FILES
  258.  
  259. The TILE Forth source is broken down into the following files:
  260.  
  261. README
  262.    This short documentation of TILE.
  263.  
  264. COPYING
  265.    The GNU General Public License.
  266.  
  267. INSTALL
  268.    Some help on how to install TILE Forth.
  269.  
  270. PORTING
  271.    Some help on how to port TILE Forth and typical problems.
  272.  
  273. Makefile
  274.    Allows a number of compilation styles for debugging, profiling, 
  275.    sharing etc. New machines and conditional compilation symbols are 
  276.    added here.
  277.  
  278. src
  279.    The C source library with the kernel code and GNU Emacs forth-mode
  280.    E-lisp source.        
  281.  
  282. lib
  283.    The Forth-83 source library for data description and management, 
  284.    high level tasking, etc.
  285.  
  286. tst
  287.    Test and example file for each Forth-83 source code file and a set
  288.    of benchmarks.
  289.  
  290. man
  291.    Manual pages for the TILE Forth C kernel and Forth-83 source code 
  292.    library.
  293.  
  294. doc
  295.    Documentation and glossaries for each source code file and kernel
  296.    vocabularies (generated by make help command).
  297.  
  298. bin
  299.    Utility commands and the TILE forth compiler/interpreter.
  300.  
  301.  
  302.  
  303. 6.    CONFIGURATION
  304.  
  305. TILE forth is targeted for 32-bit machines and no special aid is 
  306. available to allow it to be compiled for other bit-widths. The 
  307. configuration is maintained by "make" files. 
  308.  
  309. These configuration files allows a number of different modes to support
  310. typical program development phases (on C level) such as debugging, 
  311. profiling, optimization and packaging. Please see the information in
  312. these files.
  313.  
  314.  
  315. 7.    COPYING
  316.  
  317. This software is offered as shareware. You may use it freely, but 
  318. if you do use it and find it useful, you are encouraged to send the
  319. author a contribution (>= $50) to the following address:
  320.  
  321.     TILE Technology HB
  322.     Stragatan 19
  323.     S-582 67 Linkoping
  324.     SWEDEN
  325.  
  326. If you send me a contribution, I will send you the manual pages and
  327. documentation files (and paper copies if you don't have access to a 
  328. good laserprinter), and will answer questions by mail. Your name 
  329. will also be put on a distribution list for future releases.
  330.  
  331. For further information about copying see the file COPYING and
  332. the headers in the source code files. 
  333.  
  334.  
  335. 8.    NOTE
  336.  
  337. Due to the 32-bit implementation in C a number of Forth-83 definitions 
  338. are not directly confirmed. Below is a short list of words that might 
  339. give problems when porting Forth code to and from this environment:
  340.  
  341. * The Block Word Set is not supported. Source code is saved as text 
  342.   files.
  343.  
  344. * All stacks and words size are 32-bit. Special care must be taken
  345.   with memory allocation and access. Alway symbols names such as 
  346.   "cell" when allocating memory space.
  347.  
  348. * Lowercase and uppercase are distinguished, and all forth words are
  349.   lowercase. 
  350.  
  351. * A word in TILE is allowed arbitrary length as the name is stored as
  352.   as a null terminated string.
  353.  
  354. * Input such as "key" performs a read operation to the operating system
  355.   which will echo the characters.
  356.  
  357. * Variables should not allocate extra memory. "create" should be used.
  358.  
  359. * Double number arithmetic functions are not available.
  360.  
  361. Some major changes have been made to the kernel in this second release.
  362. To allow implementation of floating point numbers management and increase
  363. portability the kernel is now written in its own extendable data type 
  364. system. Some extension have become selectable such as the casting operator 
  365. in the interpreter.
  366.  
  367.  
  368. ACKNOWLEDGMENTS
  369.  
  370. First of all I wish to express my gratitude to Goran Rydqvist for helped
  371. me out with the first version of the kernel and who implemented the 
  372. forth-mode for GNU Emacs. 
  373.  
  374. Second, a special thanks to the beta test group who gave me valuable
  375. feedback. Especially Mitch Bradley, Bob Giovannucci Jr., Moises Lejter, 
  376. and Brooks David Smith. 
  377.  
  378. Last, I wish to thank the many users that have been in touch after the
  379. first releases and given me comments and encouragements.
  380.  
  381. Thank you all.
  382.